
package com.seekting.study;

public class InterrptTest {

    public static void main(String[] args) {

        new MyThread().start();
    }

    static class MyThread extends Thread {
        public boolean quit = false;
        int i = 0;

        public void quit() {
            quit = true;
            interrupt();
        }

        @Override
        public void run() {
            super.run();
            while (!quit) {

                try {
                    System.out.println("ttttt");
                    i++;
                    if (i > 5) {
                        quit();
                    } else {
                        Thread.sleep(1000);
                    }
                } catch (InterruptedException e) {
                    if (quit) {
                        return;
                    }
                }
            }
        }
    }
}
